#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <string.h>
#include <ctype.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include "errsys.h"

void stp(int signo)
{
	printf("SIGSTOP\n");
	if(signo==SIGSTOP)
		exit(0);
}

int main(int argc, char **argv)
{
	pid_t pid=fork();
	if(pid<0)
	{
		perror("fork");
		_exit(1);
	}

	if(pid==0)
	{
		signal(SIGSTOP,stp);
		for(;;);
		exit(8);
	}else{
		int status;
		kill(pid,SIGKILL);
//		kill(pid,SIGSTOP);
		sleep(1);
		wait4(pid,&status,0,NULL);
		if( WIFEXITED(status) )
		{
			printf("child exited with code:%d\n", WEXITSTATUS(status) );
		}else if( WIFSIGNALED(&status) ){
			printf("child signaled with sig:%d\n", WTERMSIG(status) );
		}else if( WIFSTOPPED(&status) ){
			printf("child signaled with sig:%d\n", WSTOPSIG(status) );
		}
	}

	return 0;
}

